﻿using System;
using Autodesk.Revit.DB;
using YJKArchMethodLibrary.Utils;

namespace YJKElementFinish.ColumnSurface.DataDefinition
{
	public class WallGeometryInfo
	{
		public Wall Component
		{
			get
			{
				return this.m_Component;
			}
		}

		public bool IsWallFace(Curve curve)
		{
			double tolerance = 0.001;
			foreach (object obj in this.m_Projection)
			{
				Curve curve2 = (Curve)obj;
				if (!(curve.GetType() != curve2.GetType()))
				{
					if (curve.GetType() == typeof(Arc))
					{
						Arc arc = curve as Arc;
						XYZ endPoint = arc.GetEndPoint(0);
						XYZ endPoint2 = arc.GetEndPoint(1);
						Arc arc2 = curve2 as Arc;
						XYZ endPoint3 = arc2.GetEndPoint(0);
						XYZ endPoint4 = arc2.GetEndPoint(1);
						if (!Geometry.IsEqual(arc.Normal, arc2.Normal))
						{
							endPoint3 = arc2.GetEndPoint(1);
							endPoint4 = arc2.GetEndPoint(0);
						}
						XYZ xyz = null;
						XYZ xyz2 = null;
						Geometry.OverlapType overlapType = Geometry.IsOverlapOfTwoArc(WallGeometryInfo.To2D(endPoint3), WallGeometryInfo.To2D(endPoint4), WallGeometryInfo.To2D(arc2.Center), WallGeometryInfo.To2D(endPoint), WallGeometryInfo.To2D(endPoint2), WallGeometryInfo.To2D(arc.Center), ref xyz, ref xyz2, tolerance);
						if (overlapType != Geometry.OverlapType._OT_Linked && overlapType != Geometry.OverlapType._OT_None)
						{
							return true;
						}
					}
					else
					{
						Line line = curve as Line;
						XYZ endPoint5 = line.GetEndPoint(0);
						XYZ endPoint6 = line.GetEndPoint(1);
						Line line2 = curve2 as Line;
						XYZ endPoint7 = line2.GetEndPoint(0);
						XYZ endPoint8 = line2.GetEndPoint(1);
						XYZ xyz3 = null;
						XYZ xyz4 = null;
						Geometry.OverlapType overlapType2 = Geometry.IsOverlapOfTwoLine(WallGeometryInfo.To2D(endPoint7), WallGeometryInfo.To2D(endPoint8), WallGeometryInfo.To2D(endPoint5), WallGeometryInfo.To2D(endPoint6), ref xyz3, ref xyz4, false, tolerance);
						if (overlapType2 != Geometry.OverlapType._OT_Linked && overlapType2 != Geometry.OverlapType._OT_None)
						{
							return true;
						}
					}
				}
			}
			return false;
		}

		public static XYZ To2D(XYZ pt)
		{
			return new XYZ(pt.X, pt.Y, 0.0);
		}

		public WallGeometryInfo()
		{
		}

		public WallGeometryInfo(WallGeometryInfo rhs)
		{
			this.m_Component = rhs.m_Component;
			foreach (object obj in rhs.m_Projection)
			{
				Curve curve = (Curve)obj;
				this.m_Projection.Append(curve);
			}
		}

		public WallGeometryInfo(Wall component, CurveArray projection)
		{
			this.m_Component = component;
			this.m_Projection = projection;
		}

		private Wall m_Component;

		private CurveArray m_Projection = new CurveArray();
	}
}
